<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page" @onTableSelection="doSelect">
      <template #headerBtn="scope">
        <el-button size="small" type="success"  icon="el-icon-share" @click="uploadKingdee(this.selection)">批量上传金蝶</el-button>
      </template>

      <template #table-handle-prepend="scope">
        <el-button size="mini" type="text" icon="el-icon-edit" @click="gotoDetail(scope.row.billNo)">查看</el-button>
        <!--        <el-button size="mini" type="text" style="color:var(&#45;&#45;el-color-success)" icon="el-icon-share" @click="uploadKingdee(scope.row.billNo)">上传金蝶</el-button>-->
      </template>
      <template #table-isUpload="scope">
        <el-tag :type="scope.row.isUpload === 'yes'? 'success': 'info'" >{{ scope.row.isUpload === 'yes'? '已上传': '未上传' }}</el-tag>
      </template>

    </vb-page>
  </div>
  <upload-dialog ref="upload_dialog" upload-method="upload_prdcol_bill" @success="uploadFinish"></upload-dialog>
  <selectRowStockIn ref="selectRowStockIn" @success=""></selectRowStockIn>
</template>

<script>
import uploadDialog from '../components/uploadDialog.vue'
import selectRowStockIn from '../components/selectRowStockInDialog.vue'

export default {
  data() {
    return {
      loading:false,
      selection: null,
      selectionLength:0,
    }
  },
  components: {
    uploadDialog,
    selectRowStockIn
  },
  methods: {
    async uploadKingdee(billNoList){
      if (!this.selection || this.selection === 0){
        this.$message.error('没有选择行')
        return
      }
      const arrBillNo = [];
      for (let i = 0;i<billNoList.length;i++){
        arrBillNo.push(billNoList[i].billNo)
      }
      try {
        let res = await this.callApi('/upload_kingdee_allocation',{billNoList:arrBillNo})
        if(!res.res){
          return
        }
        this.$message.success('上传成功')
        this.$refs.page.reload()
      }finally {
        this.loading = false
      }
    },
    doSelect(data) {
      this.selection = data
      this.selectionLength = this.selection.length;
      this.selectCount=0
      for (var i=0;i<this.selectionLength;i++){
        this.selectCount+=data[i].count
      }
      this.selectCount = parseFloat(this.selectCount).toFixed(2)
      // console.log(this.selection)
      // console.log(data[0].billNo)
    }
  }
}
</script>

<style scoped>

</style>
